package myaction.admin.courseinfo;

import myutil.DbUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class AdminCoursesPreUpdateAction extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String id = request.getParameter("c_id");
        List lstt = new ArrayList();
        try {
            Connection conn = DbUtil.getConn();
            String sql = "select c_id, c_name, DATE(c_time), c_teacher_id, c_isable from t_Courses where c_id = ?";
            PreparedStatement pstmt = conn.prepareStatement(sql);
            pstmt.setInt(1, Integer.parseInt(id));
            ResultSet rs = pstmt.executeQuery();
            while (rs.next()) {
                lstt.add(rs.getInt("c_id"));
                lstt.add(rs.getString("c_name"));
                lstt.add(rs.getString("DATE(c_time)"));
                lstt.add(rs.getString("c_teacher_id"));
                lstt.add(rs.getString("c_isable"));
            }
            rs.close();
            pstmt.close();
            conn.close();
            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.setAttribute("lstt", lstt);
        request.getRequestDispatcher("admin/courseupdate.jsp").forward(request, response);
    }

}
